export default class CollectionUtil {
  static sum(array, summer = a => a) {
    return array.reduce((result, item) => summer(item) + result, 0)
  }

  static parse(array, mapper) {
    return (array || []).map(mapper)
  }

  static isNotEmpty(array) {
    return !this.isEmpty(array)
  }

  static isEmpty(array) {
    return !array || array.length === 0
  }

  static removeElements(array = [], filter = null) {
    let i = array.length
    while (i--) {
      if (filter(array[i])) {
        array.splice(i, 1)
      }
    }
  }
}
